<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of EducationDAO
 *
 * @author gaurav
 */

require_once('FirePHPCore/FirePHP.class.php');
require_once('FirePHPCore/fb.php');
include_once 'interface/education.php';
include_once 'utility/DataBaseUtility.php';
include_once 'config/Constant.php';
include_once 'DTO/EducationDTO.php';
class EducationDAO {

    public function getEducation() {

        // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$EDUCATION_COL_EDUCATION_ID . "," .Constant::$EDUCATION_COL_EDUCATION_NAME ." FROM ".Constant::$TABLE_EDUCATION;

        $result = mysql_query($sql);
        $allEducationArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempEducation = new EducationDTO();
            $tempEducation->setId($row[Constant::$EDUCATION_COL_EDUCATION_ID]);
            $tempEducation->setName($row[Constant::$EDUCATION_COL_EDUCATION_NAME]);

            $allEducationArray[] = $tempEducation;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$EDUCATION_COL_EDUCATION_ID]. " Education Name : ". $row[Constant::$EDUCATION_COL_EDUCATION_NAME]);
            }

            //echo "<br />";
        }
        return $allEducationArray;
    } // to get all education

    public function getEducationById($educationId) {

        // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$EDUCATION_COL_EDUCATION_ID . "," .Constant::$EDUCATION_COL_EDUCATION_NAME ." FROM ".Constant::$TABLE_EDUCATION . " where ". Constant::$EDUCATION_COL_EDUCATION_ID. " = ". $educationId;
         FB::info("SQL --".$sql);
        $result = mysql_query($sql);
        $allEducationArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempEducation = new EducationDTO();
            $tempEducation->setId($row[Constant::$EDUCATION_COL_EDUCATION_ID]);
            $tempEducation->setName($row[Constant::$EDUCATION_COL_EDUCATION_NAME]);

            $allEducationArray[] = $tempEducation;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$EDUCATION_COL_EDUCATION_ID]. " Education Name : ". $row[Constant::$EDUCATION_COL_EDUCATION_NAME]);
            }

            //echo "<br />";
        }
        return $allEducationArray;

    } // to get the education by Id
    public function setEducation($educationName) {

        // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
      
        $sql = "INSERT INTO ".Constant::$TABLE_EDUCATION." (".Constant::$EDUCATION_COL_EDUCATION_NAME. ") VALUES ( '".$educationName."')";

        $result = mysql_query($sql);
        if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }

        mysql_close($connection);

    } //to insert the education
    public function setEducationByID($educationId,$educationName) {

         // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "UPDATE ".Constant::$TABLE_EDUCATION." SET ".Constant::$EDUCATION_COL_EDUCATION_NAME." = '".$educationName."' WHERE ".Constant::$EDUCATION_COL_EDUCATION_ID." = '".$educationId."'";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);

    } // to update education
    public function removeEducation() {

           // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_EDUCATION."";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);


    } // to delete the all education a
    public function removeEducationById($educationId) {

          // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_EDUCATION." where ".Constant::$EDUCATION_COL_EDUCATION_ID. " = ".$educationId;

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);

    } // to delete the education by Id
}
?>
